import { useWaasFeeOptions } from '@0xsequence/connect'
import { useEffect, useState } from 'react'
function App() {
// Use the hook with default balance checking
// This will return the wallet balance for each fee option
const [
pendingFeeOptionConfirmation,
confirmPendingFeeOption,
rejectPendingFeeOption
] = useWaasFeeOptions()
// Or skip balance checking if needed
// const [pendingFeeOptionConfirmation, confirmPendingFeeOption, rejectPendingFeeOption] =
// useWaasFeeOptions({ skipFeeBalanceCheck: true })
const [selectedFeeOptionTokenName, setSelectedFeeOptionTokenName] = useState<string>()
// Initialize with first option when fee options become available
useEffect(() => {
if (pendingFeeOptionConfirmation) {
console.log('Pending fee options: ', pendingFeeOptionConfirmation.options)
// You could select the first fee option by default
if (pendingFeeOptionConfirmation.options.length > 0) {
const firstOption = pendingFeeOptionConfirmation.options[0]
setSelectedFeeOptionTokenName(firstOption.token.symbol)
}
}
}, [pendingFeeOptionConfirmation])
// Handle fee option selection and confirmation
const handleConfirmFee = (tokenAddress: string | null) => {
if (pendingFeeOptionConfirmation) {
confirmPendingFeeOption(pendingFeeOptionConfirmation.id, tokenAddress)
}
}
// Handle fee option rejection
const handleRejectFee = () => {
if (pendingFeeOptionConfirmation) {
rejectPendingFeeOption(pendingFeeOptionConfirmation.id)
}
}
// Render fee options UI
if (pendingFeeOptionConfirmation) {
return (
<div>
<h2>Select Fee Payment Token</h2>
<div>
{pendingFeeOptionConfirmation.options.map((option) => (
<div key={option.token.symbol || option.token.contractAddress}>
<input
type="radio"
name="feeOption"
checked={selectedFeeOptionTokenName === option.token.symbol}
onChange={() => setSelectedFeeOptionTokenName(option.token.symbol)}
/>
<label>
{option.token.symbol} - {option.token.contractAddress ?
option.token.contractAddress : 'Native Token'}
{/* Display balance info if extended with balance data */}
{'balanceFormatted' in option &&
` (Balance: ${option.balanceFormatted} ${option.token.symbol})`}
</label>
</div>
))}
</div>
<div>
<button onClick={() => handleConfirmFee(
pendingFeeOptionConfirmation.options.find(
opt => opt.token.symbol === selectedFeeOptionTokenName
)?.token.contractAddress || null
)}>
Confirm
</button>
<button onClick={handleRejectFee}>Cancel</button>
</div>
</div>
)
}
return <div>No pending fee confirmation</div>
}